@extends('admin.base')
@section('title', '规格组合列表')
@section('content')
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <a class="layui-btn-sm" href="{{url('admin/home')}}">首页</a>&raquo;
            <a class="layui-btn-sm" href="/admin/shop/index?page=@if($request->page){{$request->page}}@else 1 @endif&keywords={{$request->keywords}}&label={{$request['label']}}&type={{$request['type']}}&brand={{$request['brand']}}&state={{$request['state']}}&sell={{$request['state']}}&sell={{$request['sell']}}&title={{$request->title}}&sort={{$request['sort']}}">商品列表</a>&raquo;
            <a href='' class="layui-btn-sm">{{$gname}} - 规格组合列表</a>
        </div>
    </fieldset>
    <div style="margin: 10px;">
        <div style="margin-top: 10px;width: 100%;margin-left: 10px;">

             <button class="layui-btn layui-btn-sm" style="color:#fff"><a class='home' href="{{url('admin/sku/add?id='.$id.'&page='.$request->page.'&keywords='.$request->keywords.'&label='.$request->label.'&type='.$request->type.'&brand='.$request->brand.'&state='.$request->state.'&sell='.$request->state.'&sell='.$request->sell.'&title='.$request->title.'&sort='.$request->sort)}}"  style="color:#fff">添加规格组合</a></button>
            <!-- <button class="layui-btn layui-btn-normal layui-btn-radius" onclick="layer_show('添加规格','{{url('admin/sku_add')}}?shop_id={{$id}}')">添加规格组合</button> -->
            <input type="hidden" name="id" id="shop_id" value="{{$id}}">
        </div>

        <table id="user" lay-filter="user"></table>
    </div>
    <script type="text/html" id="switchTpl">
        <input type="checkbox" name="is_hot" value="@{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="sexDemo" @{{ d.is_hot == 1 ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="image_c">
        <img onclick="active('{{url('admin/sku/edit_skupic')}}','@{{d['id']}}','编辑主图')" name="picname" src="@{{d.picname}}" height="200px" style="cursor:pointer">
    </script>
    <script type="text/html" id="barDemo">
        <!-- <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="other_pic">其余主图</a> -->
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <!-- <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a> -->
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        <a class="layui-btn layui-btn-waring layui-btn-xs  layui-btn-warm" lay-event="group">设置拼团</a>
    </script>
    <input type="hidden" name="page" value="{{$request->page}}">
    <input type="hidden" name="keywords" value="{{$request->keywords}}">
    <input type="hidden" name="label" value="{{$request->label}}">
    <input type="hidden" name="type" value="{{$request->type}}">
    <input type="hidden" name="brand" value="{{$request->brand}}">
    <input type="hidden" name="state" value="{{$request->state}}">
    <input type="hidden" name="sell" value="{{$request->sell}}">
    <input type="hidden" name="title" value="{{$request->title}}">
    <input type="hidden" name="sort" value="{{$request->sort}}">
    <input type='hidden' name='id' value="{{$request->id}}"> 
    <style>
        .layui-table-cell{
            height:130px;
            line-height: 130px;
        }
    </style>
@endsection

@section('js')
    <script>

        layui.use(['table','form'], function(){
            var table = layui.table;
            var $ = layui.jquery;
            var form = layui.form;
            var id = document.getElementById("shop_id").value;
            //alert(id)
            //第一个实例
           // console.log("data-----"+JSON.stringify(table.cache));
            table.render({
                elem: '#user'
                // ,url: '{{url('admin/sku_lists')}}' //数据接口
                ,url: '/admin/sku/sku_lists?id='+id //数据接口
                ,page: true //开启分页
                ,id:'mobileSearch'
                ,cols: [[ //表头
                    {field: 'store_id', title: '货源ID', minWidth:100, align: 'center',fixed: 'left'}
                    ,{field: 'attr', title: '规格组合', minWidth:100, align: 'center',fixed: 'left'}
                    ,{field:'picname', title: '图片',  minWidth:100,templet:'#image_c',fixed: 'left',minHeigth:200}
                    // ,{field: 'cost_price', title: '成本价', minWidth:100, align: 'center',fixed: 'left'}
                    ,{field: 'sell_price', title: '销售价', minWidth:100, align: 'center',fixed: 'left',}
                    ,{field: 'sum', title: '库存', minWidth:50, align: 'center',fixed: 'left'}
                    ,{field: 'sale_num', title: '销量', minWidth:50, align: 'center',fixed: 'left'}
                    ,{title:'操作',minWidth:300, align: 'center', toolbar: '#barDemo'}
                ]]
            });


            form.on('switch(sexDemo)', function(obj){
                var id = this.value;
                $.ajax({
                    url:'{{url('admin/spu_is_hot')}}',
                    type:'post',
                    dataType:'json',
                    data:{id:id},
                    success:function (res) {
                        if(res.code != 400){
                            layer.msg(res.data);
                        }
                    }
                });
            });

            table.on('tool(user)', function(obj){
                var data = obj.data;
                var page = $("input[name=page]").val();
                var keywords = $("input[name=keywords]").val();
                var label = $("input[name=label]").val();
                var type = $("input[name=type]").val();
                var brand = $("input[name=brand]").val();
                var state = $("input[name=state]").val();
                var sell = $("input[name=sell]").val();
                var title = $("input[name=title]").val();
                var sort = $("input[name=sort]").val();
                var id = $("input[name=id]").val();
                if(obj.event === 'del'){
                    layer.confirm('确认删除', function(index){
                        $.ajax({
                            url:'{{url('admin/sku/sku_del')}}',
                            type:'post',
                            dataType:'json',
                            data:{id:data.id},
                            success:function (res) {
                                layer.msg(res.msg);
                                var id = $("input[name=id]").val();
                                location.href='/admin/sku/index?id='+id;
                            }
                        });
                    });
                } else if(obj.event === 'edit'){
                    
                    location.href="/admin/sku/sku_edit?id="+data.id+'&page='+page+'&keywords='+keywords+'&label='+label+'&type='+type+'&brand='+brand+'&state='+state+'&sell='+sell+'&title='+title+'&sort='+sort
                    {{--layer_show('规格编辑','{{url('admin/sku_edit')}}?id='+data.id);--}}
                } else if(obj.event === 'conf'){
                    layer_show('调节账户','{{url('admin/user_conf')}}?id='+data.id,800,600);
                } else if(obj.event === 'other_pic'){
                    window.location.href="/admin/other_pic?id="+data.id;
                } else if(obj.event === 'group'){
                    location.href="/admin/group/add?typeaa=1&id="+id+"&sku_id="+data.id+'&page='+page+'&keywords='+keywords+'&label='+label+'&type='+type+'&brand='+brand+'&state='+state+'&sell='+sell+'&title='+title+'&sort='+sort
                }
            });

            //监听提交
            form.on('submit(mobile_search)', function(data){

                var search_value = data.field.search_value;

                table.reload('mobileSearch',{
                    where:{search_value:search_value},
                    page: {curr: 1}         //重新从第一页开始
                });
                return false;
            });

        });
    </script>
@endsection